<template>
  <div id="main">
    <!-- 顶部标题 -->
    <div class="title-infomation">
      <h2>用户管理</h2>
    </div>
    <!-- 功能区 -->
    <div class="table-allinfomation">
      <div id="table-info">
        <!-- 条件搜索 -->
        <div class="top-infomation">
          <el-row>
            <el-col :span="8">
              <div class="addUser">
                <el-button type="primary" @click="addUser()">添加用户</el-button>
                <el-button type="primary" @click="showJurisdictionAdmin()">权限管理</el-button>
                <el-button type="primary" @click="partyManagement()">党小组管理</el-button>

                <el-upload
                  style="margin-left:1rem"
                  action="https://www.annjong.com/bcucalculus/api/File/uploadbyExcel"
                  :limit="1"
                  :on-success="addManyUser"
                  :show-file-list="false"
                >
                  <el-button type="primary">批量添加用户</el-button>
                </el-upload>
              </div>
            </el-col>
            <el-col :span="16">
              <div class="search-info">
                <el-form v-model="searchUserInfo" :inline="true" class="search-infomation">
                  <el-form-item label="根据姓名查询信息">
                    <el-input
                      v-model="searchUserInfo"
                      clearable
                      maxlength="5"
                      show-word-limit
                      placeholder="请输入姓名"
                    />
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" @click="searchUserInfomation">查询</el-button>
                    <el-button plain @click="cleanSearchUserInfomation">重置</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </el-col>
          </el-row>
        <!-- 搜索按钮 -->
        </div>
        <!-- 表单展示 -->
        <el-table
          ref="userInfoTable"
          v-loading="loading"
          :data="userInfo.slice((currentPage-1)*pagesize,currentPage*pagesize)"
          stripe
          fit
          highlight-current-row
          class="table-infomation"
          :default-sort="{prop: 'sendScore', order: 'ascending'}"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            min-width="5%"
          />
          <el-table-column
            label="序号"
            type="index"
            min-width="12%"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="userId"
            label="用户工号"
            sortable
            :sort-orders="sortOrders"
            min-width="12%"
          />
          <el-table-column
            align="center"
            prop="userinfo.userName"
            label="用户姓名"
            min-width="12%"
          />
          <el-table-column
            align="center"
            prop="userTypeName"
            label="用户权限"
            min-width="20%"
          />
          <el-table-column
            align="center"
            prop="userinfo.userBranch"
            label="所属党小组"
            min-width="10%"
            :filters="userAllBranch"
            filter-multiple
            column-key="userinfo.userBranch"
            :filter-method="selectUserBranch"
          />
          <el-table-column
            align="center"
            label="详情"
            min-width="20%"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button type="text" @click="updateUser(scope.row)">修改</el-button>
              <el-button v-if="scope.row.userStatus === 1" type="text" @click="updateUserStatus(scope.row,0)"><p style="color:#e74c3c">封禁</p></el-button>
              <el-button v-if="scope.row.userStatus === 0" type="text" @click="updateUserStatus(scope.row,1)"><p style="color:#2ecc71">解封</p></el-button>
              <el-button type="text" @click="delUser(scope.row)"><p style="color:#e74c3c">删除</p></el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 下方内容 -->
        <el-row class="bottom-all-info">
          <!-- 功能区 -->
          <el-col :span="12">
            <div>
              <!-- 批量修改 -->
              <el-dropdown split-button type="primary">
                批量修改
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="updateGroup">批量修改党小组</el-dropdown-item>
                  <el-dropdown-item @click.native="updateType">批量修改用户权限</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </el-col>
          <el-col :span="12">
            <!-- 分页功能 -->
            <div id="pages" class="paging-info">
              <el-pagination
                :current-page="currentPage"
                :page-sizes="[5,10,15,20,30,50]"
                :page-size="pagesize"
                layout="total , sizes , prev , pager , next"
                :total="userInfo.length"
                prev-text="上一页"
                next-text="下一页"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </el-col>
        </el-row>

      </div>
    </div>
    <!-- 修改信息 -->
    <user-update ref="updateUser" />
    <!-- 添加用户 -->
    <add-userInfo ref="addUserInfo" />
    <!-- 权限管理 -->
    <jurisdiction-admin ref="jurisdictionAdmin" />
    <el-dialog
      title="批量修改用户所属小组"
      :visible.sync="isUpdateGroup"
      width="30%"
      :before-close="handleCloseUpdateGroup"
    >
      <el-table :data="chickUser">
        <el-table-column
          label="序号"
          type="index"
          min-width="12%"
          align="center"
        />
        <el-table-column
          align="center"
          prop="userId"
          label="用户工号"
          min-width="12%"
        />
        <el-table-column
          align="center"
          prop="userinfo.userName"
          label="用户姓名"
          min-width="12%"
        />
        <el-table-column
          align="center"
          prop="userinfo.userBranch"
          label="所属党小组"
          min-width="10%"
          :filters="userAllBranch"
          filter-multiple
          column-key="userinfo.userBranch"
          :filter-method="selectUserBranch"
        />
      </el-table>
      <el-form class="updateUserGroupForm">
        <el-form-item label="批量更改的所属党小组">
          <template>
            <el-select v-model="userNewBranch" filterable style="width:15rem">
              <el-option
                v-for="item in allUserBranch"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </template>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseUpdateGroup">取 消</el-button>
        <el-button type="primary" @click="submitUpdateGroup()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="批量修改用户权限"
      :visible.sync="isUpdateType"
      width="30%"
      :before-close="handleCloseUpdateType"
    >
      <el-table :data="chickUser">
        <el-table-column
          label="序号"
          type="index"
          min-width="12%"
          align="center"
        />
        <el-table-column
          align="center"
          prop="userId"
          label="用户工号"
          min-width="12%"
        />
        <el-table-column
          align="center"
          prop="userinfo.userName"
          label="用户姓名"
          min-width="12%"
        />
        <el-table-column
          align="center"
          prop="userTypeName"
          label="用户权限"
          min-width="20%"
        />
      </el-table>
      <el-form class="updateUserGroupForm">
        <el-form-item label="所有权限">
          <template>
            <template>
              <el-select
                v-model="userNewType"
                multiple
                filterable
                allow-create
                default-first-option
                style="width:15rem"
              >
                <el-option
                  v-for="item in allJurisdiction"
                  :key="item.jurisdictionId"
                  :label="item.jurisdictionName"
                  :value="item.jurisdictionId"
                />
              </el-select>
            </template>
          </template>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseUpdateType">取 消</el-button>
        <el-button type="primary" @click="submitUpdateType()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="党小组管理"
      :visible.sync="isGroup"
      width="50%"
      :before-close="handleCloseGroup"
    >
      <el-button
        type="primary"
        @click="handleGroups(1)"
      >添加党小组信息</el-button>
      <el-table :data="Groups" stripe>

        <el-table-column
          prop="branchId"
          label="党小组编号"
          width="200rpx"
        />
        <el-table-column
          prop="branchName"
          label="党小组名称"
        />
        <el-table-column
          prop="branchTypeShow"
          label="党小组类型"
        />
        <el-table-column
          align="center"
          label="操作"
          width="300px"
        >
          <template slot-scope="Scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="handleGroups(2, Scope.row.branchId)"
            >编辑</el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="deleteGroups(Scope.row.branchId)"
            >删除</el-button>
          </template>
        </el-table-column>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleCloseGroup">取 消</el-button>
          <el-button type="primary" @click="submitGroup()">确 定</el-button>
        </span>
      </el-table>
    </el-dialog>
    <el-dialog
      title=""
      :close-on-click-modal="false"
      :visible.sync="openGroup"
      :before-close="handleCloseGroup1"
      width="30%"
    >
      <el-form
        ref="Groupdata"
        :model="Groupdata"
        label-position="top"
      >
        <el-form-item
          prop="branchName"
          label="党小组名称"
          :rules="{required: true, message: '党小组名称不能为空', trigger: 'blur'}"
        >
          <el-input
            v-model="Groupdata.branchName"
            autocomplete="off"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item
          prop="branchType"
          label="党小组类型"
          :rules="{required: true, message: '党小组类型不能为空', trigger: 'blur'}"
        >
          <el-select
            v-model="Groupdata.branchType"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="a in branchTypeName"
              :key="a.value"
              :value="a.value"
              :label="a.label"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleCloseGroup1">取 消</el-button>
        <el-button
          v-if="editType == 2"
          type="primary"
          @click="updateGroups('Groupdata')"
        >修 改</el-button>
        <el-button
          v-if="editType == 1"
          type="primary"
          @click="addGroups('Groupdata')"
        >添 加</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getAllUserInfo, searchUserInfomations, updateUserStatus, updateUserInfo, updateManyUserType, delUser } from '../../api/user.js'
import { getGroups, addOneGroup, deleteOneGroup, updateOneGroup, getGroupByid } from '../../api/branch.js'
import { getAllJurisdiction } from '../../api/jurisdiction.js'
import updateUser from '../../components/updateUser/updateUser.vue'
import addUserInfo from '../../components/addUserInfo/addUserInfo.vue'
import jurisdictionAdmin from '../../components/jurisdictionAdmin/jurisdictionAdmin.vue'
export default {
  components: {
    'user-update': updateUser,
    'add-userInfo': addUserInfo,
    'jurisdiction-admin': jurisdictionAdmin
  },
  data() {
    return {
      // 获取全部数据存储位置
      userInfo: [],
      originUserInfo: [],
      routerInfo: [],
      routerAllId: [],
      sendAllUser: [],
      // 代码数据存储位置
      loading: true,
      userInfoSend: '0',
      currentPage: 1, // 默认显示页面为1
      pagesize: 20, // 每页的数据条数
      userAllBranch: [],
      branchTypeName: [
        {
          value: 1,
          label: '一般党小组'
        },
        {
          value: 2,
          label: '其他党小组'
        }
      ],
      sortOrders: [
        'ascending', 'descending'
      ],
      // 搜索设置中转值和最后值
      searchUserInfo: '', // 中转值
      searchUserName: '', // 保存值
      showStatus: false,
      thisUserInfo: [],
      multipleSelection: [],
      isUpdateGroup: false,
      isUpdateType: false,
      isGroup: false,
      openGroup: false,
      title: '', // 党小组操作标题
      editType: 1, // 党小组 1 添加 2 修改
      chickUser: [],
      Groups: [],
      Groupdata: {},
      userNewBranch: '',
      userNewType: [],
      allUserBranch: [],
      allJurisdiction: []
    }
  },
  computed: {
  },
  watch: {
  },
  created() {
    // 获取所有用户信息
    this.getAllUserInfo()
  },
  methods: {
    // 全部调用方法

    // 获取所有用户信息
    getAllUserInfo() {
      var that = this
      new Promise(function(resolve, reject) {
        getGroups().then((data) => {
          const userAllBranch = []
          const allUserBranch = []
          for (const i in data.obj) {
            const userBranch = {
              value: data.obj[i].branchName,
              text: data.obj[i].branchName
            }
            const userBranchInfo = {
              value: data.obj[i].branchId,
              label: data.obj[i].branchName
            }
            userAllBranch.push(userBranch)
            allUserBranch.push(userBranchInfo)
          }
          that.userAllBranch = userAllBranch
          that.allUserBranch = allUserBranch
          getAllUserInfo().then((res) => {
            const userInfo = res.obj
            for (var i = 0; i < userInfo.length; i++) {
              userInfo[i].userinfo.userBranchNum = userInfo[i].userinfo.userBranch
              userInfo[i].userinfo.userBranch = data.obj.find(item => item.branchId === userInfo[i].userinfo.userBranch).branchName
            }
            resolve(userInfo)
          })
        })
      }).then((data) => {
        new Promise(function(resolve, reject) {
          resolve(data)
        }).then((data1) => {
          that.findTypeName(data1)
        })
      })
    },
    // 根据id找到对应信息
    findTypeName(user) {
      var that = this
      // 获取全部了路由信息
      new Promise(function(resolve, reject) {
        getAllJurisdiction().then(res => {
          resolve(res.obj)
        })
      }).then((data) => {
        // 保存全部路由信息
        that.allJurisdiction = data
        // 切分用户类型
        for (var i = 0; i < user.length; i++) {
          var userTypeNum = user[i].userType.split(',')
          for (var j = 0; j < userTypeNum.length; j++) {
            for (var x = 0; x < data.length; x++) {
              if (data[x].jurisdictionId === userTypeNum[j]) {
                userTypeNum[j] = data[x].jurisdictionName
              }
            }
          }
          var userTypeALlName = ''
          // 把数组转换成字符串
          for (var y = 0; y < userTypeNum.length; y++) {
            if (y < userTypeNum.length - 1) {
              userTypeALlName += userTypeNum[y] + '、'
            } else {
              userTypeALlName += userTypeNum[y]
            }
          }
          // 把值存入到user中
          user[i].userTypeName = userTypeALlName
        }
        that.userInfo = user
        that.loading = false
      })
    },
    // 修改信息
    updateUser(user) {
      this.$refs.updateUser.showDialog(user)
    },
    // 添加用户
    addUser() {
      this.$refs.addUserInfo.showDialog()
    },
    // 权限管理
    showJurisdictionAdmin() {
      this.$refs.jurisdictionAdmin.showDialog(this.allJurisdiction)
    },
    // 删除用户
    delUser(user) {
      var that = this
      var userId = user.userId
      var userName = user.userinfo.userName
      this.$confirm('您是否删除' + userName + '（' + userId + '）' + '的用户信息，点击确定后删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delUser(userId).then(res => {
          if (res.obj === null) {
            that.show = false
            that.$message({
              message: '删除成功',
              type: 'success'
            })
            top.location.reload()
          } else {
            that.$message({
              message: '服务器异常，请稍后重试',
              type: 'success'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 封禁用户
    updateUserStatus(user, userStatus) {
      var that = this
      this.$confirm('此操作将会导致该用户无法进入系统，请确定是否封禁', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateUserStatus(user, userStatus).then(res => {
          if (res.obj === null) {
            that.show = false
            that.$message({
              message: '封禁成功',
              type: 'success'
            })
            top.location.reload()
          } else {
            that.$message({
              message: '服务器异常，请稍后重试',
              type: 'success'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消封禁'
        })
      })
    },
    // 党小组管理
    partyManagement() {
      var that = this
      this.isGroup = true
      getGroups().then(data => {
        that.Groups = data.obj
        for (let index = 0; index < that.Groups.length; index++) {
          if (data.obj[index].branchType === 1) {
            that.$set(that.Groups[index], 'branchTypeShow', '一般党小组')
          } else if (data.obj[index].branchType === 2) {
            that.$set(that.Groups[index], 'branchTypeShow', '其他党小组')
          }
        }
      })
    },
    // 删除党小组
    deleteGroups(id) {
      var that = this
      this.$confirm('确认删除该党小组？').then(() =>
        deleteOneGroup(id).then(data => {
          this.$notify({
            title: '操作成功',
            type: 'success'
          })
        }).then(data => {
          that.Groups = []
          that.partyManagement()
        })
      )
    },
    // 修改党小组
    updateGroups(formName) {
      var that = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateOneGroup(that.Groupdata).then(data => {
            if (data.result === true) {
              that.$notify({
                title: '修改成功',
                type: 'success'
              })
              that.Groupdata = {}
              this.partyManagement()
              this.openGroup = false
            } else {
              this.$notify({
                title: '修改失败',
                type: 'error'
              })
              that.Groupdata = {}
              this.partyManagement()
              this.openGroup = false
            }
          })
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    // 增加党小组
    addGroups(formName) {
      var that = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          addOneGroup(that.Groupdata).then(data => {
            if (data.result === true) {
              that.$notify({
                title: '增加成功',
                type: 'success'
              })
              that.Groupdata = {}
              this.partyManagement()
              this.openGroup = false
            } else {
              this.$notify({
                title: '增加失败',
                type: 'error'
              })
              that.Groupdata = {}
              this.partyManagement()
              this.openGroup = false
            }
          })
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    handleGroups(type, id) {
      var that = this
      that.editType = type
      that.openGroup = true
      if (type === 2) {
        getGroupByid(id).then(data => {
          that.$set(that.Groupdata, 'branchName', data.obj.branchName)
          that.$set(that.Groupdata, 'branchId', data.obj.branchId)
          that.$set(that.Groupdata, 'branchType', data.obj.branchType)
          if (data.obj.branchType === 1) {
            that.$set(that.Groupdata, 'branchTypeShow', '一般党小组')
          } else if (data.obj.branchType === 2) {
            that.$set(that.Groupdata, 'branchTypeShow', '其他党小组')
          }
        })
      }
    },
    // 搜索页面信息
    searchUserInfomation() {
      var that = this
      var searchUserInfo = this.searchUserInfo
      if (searchUserInfo === '' || searchUserInfo === null || searchUserInfo === undefined) {
        if (that.originUserInfo.length !== 0) {
          that.userInfo = that.originUserInfo
        }
      } else {
        if (that.searchUserInfoStatus !== 1) {
          that.originUserInfo = that.userInfo
        }
        new Promise(function(resolve, reject) {
          searchUserInfomations(searchUserInfo).then(res => {
            resolve(res.obj)
          })
        }).then((data) => {
          if (data.length !== 0) {
            var giveUserInfo = []
            that.searchUserInfoStatus = 1
            new Promise(function(resolve, reject) {
              if (that.searchUserInfoStatus !== 1) {
                for (var i = 0; i < data.length; i++) {
                  var newUserInfo = that.userInfo.filter(function(val) {
                    return val.userId === data[i].userId
                  })
                  giveUserInfo.push(newUserInfo[0])
                  resolve(giveUserInfo)
                }
              } else {
                for (var j = 0; j < data.length; j++) {
                  var newUserInfo1 = that.originUserInfo.filter(function(val) {
                    return val.userId === data[j].userId
                  })
                  giveUserInfo.push(newUserInfo1[0])
                  resolve(giveUserInfo)
                }
              }
            }).then((data) => {
              that.userInfo = data
            })
          } else if (data.length === 0) {
            this.$message({
              type: 'warning',
              message: '未搜索到数据'
            })
          } else {
            this.$message({
              type: 'warning',
              message: '服务器异常，请稍后再试'
            })
          }
        })
      }
    },
    // 批量添加用户
    addManyUser(response, file, fileList) {
      this.$message({
        type: 'success',
        message: '上传成功'
      })
    },
    // 页面逻辑方法
    handleClose() {
      this.dialogFormVisible = false
      this.is_show_judge = false
      this.send = []
      this.list = []
      this.fetchData()
    },
    // 选择党小组
    selectUserBranch(value, row, column) {
      return row.userinfo.userBranch === value
    },
    // 清空全部筛选
    cleanSearchUserInfomation() {
      var that = this
      this.$message({
        message: '重置成功',
        type: 'success'
      })
      if (that.originUserInfo.length !== 0) {
        that.userInfo = that.originUserInfo
      }
      this.searchUserInfo = ''
      this.$refs.userInfoTable.clearFilter()
    },
    handleSizeChange(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
    },
    // 切换选择用户的时候进行赋值
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    updateGroup() {
      if (this.multipleSelection.length === 0) {
        this.$message({
          message: '请至少勾选一项，再进行操作',
          type: 'warning'
        })
      } else {
        this.showUpdateGroup()
      }
    },
    updateType() {
      if (this.multipleSelection.length === 0) {
        this.$message({
          message: '请至少勾选一项，再进行操作',
          type: 'warning'
        })
      } else {
        this.showUpdateType()
      }
    },
    showUpdateGroup() {
      this.chickUser = this.multipleSelection
      this.isUpdateGroup = true
    },
    showUpdateType() {
      this.chickUser = this.multipleSelection
      this.isUpdateType = true
      this.getJurisdiction()
    },
    handleCloseUpdateGroup() {
      this.$confirm('是否确定取消', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.chickUser = []
        this.isUpdateGroup = false
        // 判断是否选择了党小组，如果选择了，删除它
        if (this.userNewBranch !== '') {
          this.userNewBranch = ''
        }
        this.$message({
          type: 'success',
          message: '取消修改成功'
        })
      }).catch(() => {})
    },
    handleCloseUpdateType() {
      this.$confirm('是否确定取消', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.chickUser = []
        this.isUpdateType = false
        // 判断是否选择了党小组，如果选择了，删除它
        if (this.userNewType !== []) {
          this.userNewType = []
        }
        this.$message({
          type: 'success',
          message: '取消修改成功'
        })
      }).catch(() => {})
    },
    handleCloseGroup() {
      this.$confirm('是否确定取消', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.isGroup = false
        this.$message({
          type: 'success',
          message: '取消成功'
        })
      }).catch(() => {})
    },
    handleCloseGroup1() {
      this.$confirm('是否确定取消', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.openGroup = false
        this.$message({
          type: 'success',
          message: '取消成功'
        })
      }).catch(() => {})
    },
    submitUpdateGroup() {
      var that = this
      var chickUserName = ''
      var chickGroup = ''
      if (this.userNewBranch === 1) {
        chickGroup = '第一党小组'
      } else if (this.userNewBranch === 2) {
        chickGroup = '第二党小组'
      } else if (this.userNewBranch === 3) {
        chickGroup = '第三党小组'
      } else if (this.userNewBranch === 4) {
        chickGroup = '第四党小组'
      } else if (this.userNewBranch === 5) {
        chickGroup = '第五党小组'
      } else if (this.userNewBranch === 0) {
        chickGroup = '不属于任何党小组'
      } else if (this.userNewBranch === 7) {
        chickGroup = '其他'
      }
      for (let i = 0; i < this.chickUser.length; i++) {
        chickUserName = chickUserName + this.chickUser[i].userinfo.userName + ' '
      }
      if (this.userNewBranch.length === 0) {
        this.$message({
          showClose: true,
          message: '请选择要修改的党小组！',
          type: 'error'
        })
      } else {
        this.$confirm('是否确定将用户：' + chickUserName + '的所属党小组修改为' + chickGroup + '?', '确认修改', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          for (let j = 0; j < that.chickUser.length; j++) {
            that.chickUser[j].userBranch = this.userNewBranch
            updateUserInfo(that.chickUser[j]).then(() => {
            })
          }
          that.$message('正在提交中')
          setTimeout(() => {
            this.$message({
              type: 'success',
              message: '修改成功！'
            })
            that.getAllUserInfo()
            that.chickUser = []
            that.isUpdateGroup = false
            that.userNewBranch = ''
          }, 2000)
        }).catch(() => {})
      }
    },
    submitUpdateType() {
      var that = this
      var chickUserName = ''
      var chickType = ''
      var userType = that.userNewType.toString()
      for (let j = 0; j < this.userNewType.length; j++) {
        if (this.userNewType[j] === 0) {
          chickType = chickType + '超级管理员 '
        } else if (this.userNewType[j] === 1) {
          chickType = chickType + '支部书记 '
        } else if (this.userNewType[j] === 2) {
          chickType = chickType + '支部副书记 '
        } else if (this.userNewType[j] === 3) {
          chickType = chickType + '组织委员 '
        } else if (this.userNewType[j] === 4) {
          chickType = chickType + '宣传委员 '
        } else if (this.userNewType[j] === 5) {
          chickType = chickType + '纪检委员 '
        } else if (this.userNewType[j] === 6) {
          chickType = chickType + '党小组长 '
        } else if (this.userNewType[j] === 7) {
          chickType = chickType + '青年委员 '
        } else if (this.userNewType[j] === 8) {
          chickType = chickType + '个人 '
        }
      }
      for (let i = 0; i < this.chickUser.length; i++) {
        chickUserName = chickUserName + this.chickUser[i].userinfo.userName + ' '
      }
      if (this.userNewType.length === 0) {
        this.$message({
          showClose: true,
          message: '请至少选择一项权限！',
          type: 'error'
        })
      } else if (userType.indexOf('8') === -1) {
        that.$confirm('当前用户无个人权限，若无个人权限则无法在用户端进行登录。点击取消返回修改，点击确定开始提交。', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          for (let j = 0; j < that.chickUser.length; j++) {
            that.chickUser[j].userType = userType
            updateManyUserType(that.chickUser[j]).then(() => {
            })
          }
          that.$message('正在提交中')
          setTimeout(() => {
            this.$message({
              type: 'success',
              message: '修改成功！'
            })
            that.getAllUserInfo()
            that.chickUser = []
            that.isUpdateType = false
            that.userNewType = []
          }, 2000)
        }).catch(() => {})
      } else {
        this.$confirm('是否确定将用户：' + chickUserName + '的权限修改为：' + chickType + '?', '确认修改', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          for (let j = 0; j < that.chickUser.length; j++) {
            that.chickUser[j].userType = userType
            updateManyUserType(that.chickUser[j]).then(() => {
            })
          }
          that.$message('正在提交中')
          setTimeout(() => {
            this.$message({
              type: 'success',
              message: '修改成功！'
            })
            that.getAllUserInfo()
            that.chickUser = []
            that.isUpdateType = false
            that.userNewType = []
          }, 2000)
        }).catch(() => {})
      }
    },
    submitGroup() {

    },
    // 获取所有权限id和名称
    getJurisdiction() {
      getAllJurisdiction().then((res) => {
        res.obj.splice(0, 1)
        this.allJurisdiction = res.obj
      })
    }
  }
}
</script>

<style scope>
#main{
  margin-left: 5px;
  margin-right: 5px;
  margin-bottom: 10rem;
}
#table-area{
  margin-left: 0.8rem;
  margin-right: 0.8rem;
}
.title-infomation{
  margin-top:3rem;
  margin-left: 4rem;
}
.table-info{
  margin-left: 7rem;
  margin-right: 10rem;
}
.table-infomation{
  width: 100rem;
}
.bottom-all-info{
  margin-top: 2rem;
}
.paging-info{
  float: right;
}
.reset-userType{
    margin-top: 2rem;
}
.search-info{
    display: flex;
  margin-top:3rem;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
  margin-right: 3rem;
}
.addUser{
  display: flex;
  margin-top:3rem;
  margin-bottom: 1.5rem;
}
.table-allinfomation{
  margin-left: 7rem;
  margin-right: 5rem;
}
.updateUserGroupForm{
  margin-top: 3rem;
  margin-left: 1.5rem;
}
</style>
